<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class PrivilegeController extends Controller
{
	//权限管理首页
    public function getIndex()
    {
        //解析页面
        return view('department/privilege/add');

    } 

    //添加
    public function getAdd()
    {
        $role = DB::table('role')->get();
        // dd($role);
        return view('department/privilege/add',['role'=>$role]);

    }

    //修改权限
    public function postInsert(Request $request)
    {
        $this->validate($request, [
        'PersonName' => 'required|exists:person,PersonName',
        'Authority' => 'required',
        ],[
        'PersonName.required'=>'员工名不能为空',
        'PersonName.exists'=>'员工名不存在',
        'roleId.required'=>'角色不能为空',
        ]);
    	$res = $request->only('PersonName','Authority');
    	// dd($res);
        //执行修改
        DB::table('person')->where('PersonName',$res['PersonName'])->update($res);
        return redirect('department/privilege/add');
        
    }
    
}
